package cst.a000wxb.recyclertest115wxb.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cst.a000wxb.recyclertest115wxb.model.ArticleModel;
import cst.a000wxb.recyclertest115wxb.R;
import cst.a000wxb.recyclertest115wxb.adapter.MyAdapter;
import cst.a000wxb.recyclertest115wxb.bean.ArticleBean;
import cst.a000wxb.recyclertest115wxb.iface.ArticleListener;
import cst.a000wxb.recyclertest115wxb.model.ArticleModel;
import cst.a000wxb.recyclertest115wxb.adapter.MyAdapter;
import cst.a000wxb.recyclertest115wxb.bean.ArticleBean;
import cst.a000wxb.recyclertest115wxb.iface.ArticleListener;

public class MainActivity extends AppCompatActivity implements ArticleListener{
    private List<ArticleBean> list;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    private void initRecyclerView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerView);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        // list=getData();
        mAdapter=new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }

   /* private List<ArticleBean>getData(){
        List<ArticleBean>list=new ArrayList<ArticleBean>();
        ArticleBean art;
        art=new ArticleBean();
        art.setArticleId(1);
        art.setTime("2017-4-1 15:16");
        art.setImgid(R.drawable.f1);
        list.add(art);
        art.setTitle("标题1");
        art.setDescription("描述1");
        art=new ArticleBean();
        art.setArticleId(2);
        art.setTime("2017-4-2 15:16");
        art.setImgid(R.drawable.f2);
        list.add(art);
        art.setTitle("标题2");
        art.setDescription("描述2");
        art=new ArticleBean();
        art.setArticleId(3);
        art.setTime("2017-4-3 15:16");
        art.setImgid(R.drawable.f3);
        list.add(art);
        art.setTitle("标题3");
        art.setDescription("描述3");
        art=new ArticleBean();
        art.setArticleId(4);
        art.setTime("2017-4-4 15:16");
        art.setImgid(R.drawable.f4);
        list.add(art);
        art.setTitle("标题4");
        art.setDescription("描述4");
        art=new ArticleBean();
        art.setArticleId(5);
        art.setTime("2017-4-5 15:16");
        art.setImgid(R.drawable.f5);
        list.add(art);
        art.setTitle("标题5");
        art.setDescription("描述5");
        art=new ArticleBean();
        art.setArticleId(6);
        art.setTime("2017-4-6 15:16");
        art.setImgid(R.drawable.f6);
        list.add(art);
        art.setTitle("标题6");
        art.setDescription("描述6");
        return list;
    }*/

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);
    }


    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "fail:"+msg, Toast.LENGTH_SHORT).show();
    }
}
